<?php

/**
 * XHTML_All_Attributes_Element, xhtml_lib
 * 
 * This file contains the source code for the XHTML_All_Attributes_Element 
 * class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Focus_Attributes.php";
include_once "XHTML_Common_Element.php";

/**
 * The XHTML_All_Attributes_Element abstract class implements the all the 
 * atributes and methods for some of the xhtml elements as a part of a 
 * xhtml-strict php-handler implementation.
 */
abstract class XHTML_All_Attributes_Element extends XHTML_Common_Element
implements XHTML_Focus_Attributes {
    
    /**
     * Key char for the accesskey xhtml-focus-attribute.
     *
     * @var string
     */
    protected $accessKey;
    
    /**
     * Number for the tabindex xhtml-focus-attribute.
     *
     * @var integer
     */
    protected $tabIndex;
    
    /**
     * Script for the onfocus xhtml-focus-attribute.
     *
     * @var string
     */
    protected $onFocusScript;
    
    /**
     * Script for the onblur xhtml-focus-attribute.
     *
     * @var string
     */
    protected $onBlurScript;
    
    
    // Method implementation for the XHTML_Focus_Attributes interface.
    
    /**
     * Sets the accessibility key character for this element.
     *
     * @param string $string
     */
    function setAccessKey($char)
    {
        $this->accessKey = $char;
    }
    
    /**
     * Gets the accesibility key characater that has been set for this element.
     *
     * @return string
     */
    function getAccessKey()
    {
        return $this->accessKey;
    }
    
    /**
     * Sets the tabulation index for this element.
     *
     * @param integer $index
     */
    function setTabIndex($index)
    {
        $this->tabIndex = $index;
    }
    
    /**
     * Gets the tabulation index that has been set for this element.
     *
     * @return integer
     */
    function getTabIndex()
    {
        return $this->tabIndex;
    }
    
    /**
     * Sets the onfocus event script for this element.
     *
     * @param string $script
     */
    function setOnFocus($script)
    {
        $this->onFocusScript = $script;
    }
    
    /**
     * Gets the onfocus event script that has been set for this element.
     *
     * @return string
     */
    function getOnFocus()
    {
        return $this->onFocusScript;
    }
    
    /**
     * Sets the onblur event script for this element.
     *
     * @param string $script
     */
    function setOnBlur($script)
    {
        $this->onBlurScript = $script;
    }
    
    /**
     * Gets the onblur event script that has been set for this element.
     *
     * @return string
     */
    function getOnBlur()
    {
        return $this->onBlurScript;
    }
    
    
    // Overriding the toString method.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = parent::toString();
        
        // An attribute is added to the return string only if it is set.
        
        if (isset($this->accessKey)) {
            $auxString = $auxString."accesskey=\"".$this->accessKey."\" ";
        }
        
        if (isset($this->tabIndex)) {
            $auxString = $auxString."tabindex=\"".$this->tabIndex."\" ";
        }
        
        if (isset($this->onFocusScript)) {
            $auxString = $auxString."onfocus=\"".$this->onFocusScript."\" ";
        }
        
        if (isset($this->onBlurScript)) {
            $auxString = $auxString."onblur=\"".$this->onBlurScript."\" ";
        }
        
        return $auxString;
    }
    
}

?>